const helper = require("./../util/helper");
const Path = require('path');

const config = {
    getCommonConfig(option) {
        return helper.extend(true, {
            name: '',
            map: {},
            info: {
                title: "ada",
                icons: [],
                short_name: "ada",
                start_url: "/",
                display: "standalone",
                background_color: "#fff",
                theme_color: "#fff",
                description: "ada web framework.",
                related_applications: [{ "platform": "web" }],
                keywords: "",
                charset: "UTF-8",
                meta: [
                    { name: 'viewport', content: "width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no" },
                    { name: 'format_detection', content: "telephone=no" },
                    { name: 'apple_mobile_web_app_status_bar_style', content: "white" },
                    { name: 'apple_mobile_web_app_capable', content: "yes" }
                ],
                link: [],
                style: [],
                script: []
            },
            apps: [],
            server: {
                enable: true,
                protocol: "http",
                host: "localhost",
                port: "8080",
                serverPath: "./server.js",
                nofoundPathCheck(path) {
                    return path.indexOf('.') !== -1;
                },
                proxy: []
            },
            ssr: {
                urls: [],
                output: ""
            }
        }, option || {});
    },
    getPackerConfig(option) {
        if (!option) {
            option = {};
        }
        let defaultOption = {
            basePath: "./app/",
            distPath: "./dist/",
            sourcePath: "./src/",
            entryPath: "./src/entries",
            staticPath: "./src/static",
            hookerPath: "./src/index.js",
            main: "./src/root.js",
            develop: false,
            hook: function () { },
            style: [],
            script: [],
            ignore: [],
            alias: {},
            watchNodeModules: false,
            // entryFiles() {
            //     return [];
            // },
            singleFiles() {
                return [];
            },
            worker: {
                path: "",
                scope: "/"
            },
            output: {
                files: true,
                packFiles: true,
                staticFiles: true
            },
            dependence: {
                js: {
                    "uglify-es": "^3.3.8",
                    "babel-preset-ada": "",
                    "babel-preset-ada-core": "",
                    "koa": ""
                },
                css: {
                    "autoprefixer": "^7.1.6",
                    "postcss": "^5.2.5",
                    "uglifycss": "^0.0.25",
                    "html-minifier": "^3.5.6"
                },
                scss: {
                    "autoprefixer": "^7.1.6",
                    "postcss": "^5.2.5",
                    "uglifycss": "^0.0.25",
                    "sass": "^1.25.0",
                    "html-minifier": "^3.5.6"
                },
                less: {
                    "autoprefixer": "^7.1.6",
                    "postcss": "^5.2.5",
                    "uglifycss": "^0.0.25",
                    "less": "^2.7.1",
                    "html-minifier": "^3.5.6"
                },
                json: {},
                html: {
                    "html-minifier": "^3.5.6"
                },
                icon: {
                    "svgo": "^1.3.2"
                }
            },
            maker: {
                babel: './maker/babel.js',
                minify: './maker/minifier.js',
                postcss: './maker/postcss.js',
                sass: './maker/sass.js',
                typescript: './maker/typescript.js',
                uglify: './maker/uglify.js',
                uglifycss: './maker/uglifycss.js',
                icon: './maker/icon.js',
                html: './maker/html.js',
                json: './maker/json.js',
                less: './maker/less.js'
            },
            adaCore: {
                presets: ["babel-preset-ada-core"]
            },
            sourcemap: false,
            compiler: {
                babel: {
                    presets: ["babel-preset-ada"]
                },
                uglify: {},
                uglifycss: {},
                postcss: {
                    autoprefixer: {}
                },
                sass: {
                    importer(url) {
                        if (url[0] !== '.' || url[0] !== '/') {
                            return {
                                file: Path.resolve(process.cwd(), './node_modules', `./${url}`)
                            }
                        }
                    }
                },
                minify: {},
                less: {},
                icon: {
                    plugins: [
                        { cleanupAttrs: true },
                        { removeDoctype: true },
                        { removeXMLProcInst: true },
                        { removeComments: true },
                        { removeMetadata: true },
                        { removeTitle: true },
                        { removeDesc: true },
                        { removeUselessDefs: true },
                        { removeEditorsNSData: true },
                        { removeEmptyAttrs: true },
                        { removeHiddenElems: true },
                        { removeEmptyText: true },
                        { removeEmptyContainers: true },
                        { removeViewBox: false },
                        { cleanupEnableBackground: true },
                        { convertStyleToAttrs: true },
                        { convertColors: true },
                        { convertPathData: true },
                        { convertTransform: true },
                        { removeUnknownsAndDefaults: true },
                        { removeNonInheritableGroupAttrs: true },
                        { removeUselessStrokeAndFill: true },
                        { removeUnusedNS: true },
                        { cleanupIDs: true },
                        { cleanupNumericValues: true },
                        { moveElemsAttrsToGroup: true },
                        { moveGroupAttrsToElems: true },
                        { collapseGroups: true },
                        { removeRasterImages: false },
                        { mergePaths: true },
                        { convertShapeToPath: true },
                        { sortAttrs: true },
                        { removeDimensions: true },
                        { removeAttrs: { attrs: '(stroke|fill)' } }
                    ]
                }
            },
            make: null
        };
        if (option.develop) {
            defaultOption.make = {
                js: ['babel'],
                css: ['postcss'],
                scss: ['sass', 'postcss'],
                less: ['less', 'postcss'],
                json: ['json'],
                html: ['html'],
                icon: ['icon'],
                ts: ['typescript']
            }
        } else {
            defaultOption.make = {
                js: ['babel', 'uglify'],
                css: ['postcss', 'uglifycss'],
                scss: ['sass', 'postcss', 'uglifycss'],
                less: ['less', 'postcss', 'uglifycss'],
                json: ['json'],
                html: ['html'],
                icon: ['icon'],
                ts: ['typescript', 'uglify']
            }
        }
        return helper.extend(true, defaultOption, option || {});
    }
};
module.exports = config;